<?php
class SP_Helper_Cookie
{
	protected static $data;
	
	public static function set($name, $value, $params=array())
	{
		$expire = 0;
		$path='';
		$domain='';
		$secure = false;
		$httponly = false;
		extract($params, EXTR_IF_EXISTS);
		if( $domain==':all' )
		{
			$host=$_SERVER['HTTP_HOST'];
			$domains=explode('.', $host);
			$count=count($domains);
			$domain='.'.$domains[$count-2].'.'.$domains[$count-1];
		}
		return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
	}

	public static function has($name)
	{
		return array_key_exists($name, $_COOKIE);
	}
	
	public static function get($name,$value=null)
	{
		return self::has($name) ? $_COOKIE[$name] : $value;
	}
	
	public static function remove($name)
	{
		setcookie($name, '');
	}
	
	public function getAll()
	{
		return $_COOKIE;
	}
}